from sqlmodel import Field, SQLModel
from sqlalchemy import JSON
from datetime import datetime

class WikipediaPage(SQLModel, table=True):
    id: int | None = Field(default=None, primary_key=True)
    page_id: int | None = Field(index=True)
    query_title: str = Field(index=True)
    title: str = Field(index=True)
    lang: str = Field()
    wikibase_item: str|None = Field(index=True)
    wikibase_shortdesc: str|None
    description: str | None = Field()
    image: str | None = Field()
    extract: str | None = Field()
    categories: list[str] = Field(default=[], sa_type=JSON, sa_column_kwargs={"comment": "categories"}) 
    images_list: list[dict] = Field(default=[], sa_type=JSON, sa_column_kwargs={"comment": "images"}) 
    image_info: list[dict] | None = Field(default=[], sa_type=JSON, sa_column_kwargs={"comment": "file image info"}) 
    # 添加时间戳字段
    created_at: datetime = Field(default_factory=datetime.utcnow)
    updated_at: datetime = Field(default_factory=datetime.utcnow, index=True)
    
    

class WikipediaWikiText(SQLModel, table=True):
    id: int | None = Field(default=None, primary_key=True)
    page_id: int | None = Field(index=True)
    query_title: str = Field(index=True)
    title: str | None = Field(index=True)
    lang: str = Field()
    wikitext: str | None = Field() 
    langlinks: dict = Field(default=[], sa_type=JSON, sa_column_kwargs={"comment": "langlinks"}) 
    sections: list[dict] = Field(default=[], sa_type=JSON,)   
  
    # 添加时间戳字段
    created_at: datetime = Field(default_factory=datetime.utcnow)
    updated_at: datetime = Field(default_factory=datetime.utcnow, index=True)
    
    

class WikipediaCategoryMember(SQLModel, table=True):
    id: int | None = Field(default=None, primary_key=True)
    page_id: int | None = Field(index=True)
    query_title: str | None = Field(index=True)
    # title: str | None = Field(index=True)
    lang: str = Field()
    
    subcategories: list | None = Field(sa_type=JSON,)
    pages: list | None = Field(sa_type=JSON,)  
  
    # 添加时间戳字段
    created_at: datetime = Field(default_factory=datetime.utcnow)
    updated_at: datetime = Field(default_factory=datetime.utcnow, index=True)
    